package data;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;

public class PayType extends AbstractData{
	private long id = -1;
	private long hotelId;
	private String title;
	private PayModeMaster mode;
	private String modeString;
	private boolean status;
	private boolean avaliable;
	private String description;
	
	public PayType()
	{
		status = true;
		avaliable = true;
	}
	
	public PayType(long id){
		this.id = id;
		this.status = true;
		this.avaliable = true;
	}
	
	public void setId(long id) {
		this.id = id;
	}
	
	public long getId() {
		return id;
	}

	public long getHotelId() {
		return hotelId;
	}
	public void setHotelId(long hotelId) {
		this.hotelId = hotelId;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public PayModeMaster getMode() {
		if (mode == null && !(modeString == null || modeString.isEmpty())) {
			PayModeMaster m = new PayModeMaster(Long.parseLong(modeString));
			m.LoadData();
			mode = m;
		}
		return mode;
	}

	public void setMode(PayModeMaster mode) {
		this.modeString = String.format("%d", mode.getId());
		this.mode = mode;
	}
	public boolean isStatus() {
		return status;
	}
	public void setStatus(boolean status) {
		this.status = status;
	}
	public boolean isAvaliable() {
		return avaliable;
	}
	public void setAvaliable(boolean avaliable) {
		this.avaliable = avaliable;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}

	@Override
	public Entity getEntity() {
		Entity item;
		if(this.key == null)
			item = new Entity(EntityName.PayType);
		else
			item = new Entity(this.key);

		item.setProperty("hotelId", this.hotelId);
		item.setProperty("title", this.title);
		item.setProperty("Status", this.status);
		item.setProperty("Avaliable", this.avaliable);
		item.setProperty("Mode", this.modeString);
		item.setProperty("Description", this.description);
		
		return item;
	}

	@Override
	public void setEntity(Entity entity) {
		this.id = entity.getKey().getId();
		this.hotelId = (Long) entity.getProperty("hotelId");
		this.title = (String) entity.getProperty("title");
		this.status = (Boolean) entity.getProperty("Status");
		this.avaliable = (Boolean) entity.getProperty("Avaliable");
		this.modeString = (String) entity.getProperty("Mode");
		this.description = (String) entity.getProperty("Description");

		this.key = entity.getKey();
	}
	
	public void LoadData() {
		if (this.id > -1) {
			Entity entity = LoadData(EntityName.PayType, this.id);
			setEntity(entity);
		}
	}

}
